package Java9_16;

import java.io.*;
import java.util.*;

public class Work2 {
    public static void main(String[] args) {
        try {
            ObjectInputStream oi = new ObjectInputStream(new FileInputStream("D:\\rubbish\\shuangseqiu.txt"));
            List<Integer> list2 = (List<Integer>) oi.readObject();
            oi.close();
            System.out.println("中奖号码：" + list2);
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入购买的彩票号码：");
            List<Integer> list1 = new ArrayList<>();
            for (int i = 0; i < 6; i++) {
                list1.add(sc.nextInt());
            }
            list1.add(sc.nextInt());
            System.out.println(list1);
            int count = 0;
            boolean blue = false;
            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 6; j++) {
                    if (list1.get(i).equals(list2.get(j))) {
                        count++;
                    }
                }
            }
            if (list1.get(6).equals(list2.get(6))) {
                blue = true;
            }
            if (count == 6 && blue) {
                System.out.println("获得一等奖！");
            } else if (count == 6) {
                System.out.println("获得二等奖！");
            } else if (count == 5 && blue) {
                System.out.println("获得三等奖！");
            } else if (count == 5 || (count == 4 && blue)) {
                System.out.println("获得四等奖！");
            } else if (count == 4 || (count == 3 && blue)) {
                System.out.println("获得五等奖！");
            } else if (blue) {
                System.out.println("获得六等奖！");
            } else {
                System.out.println("很遗憾，没有中奖！");
            }
        } catch (Exception e) {
            List<Integer> list = new ArrayList<>();
            Random r = new Random();
            while (list.size() < 6) {
                int a = r.nextInt(33) + 1;
                if (!list.contains(a)) {
                    list.add(a);
                }
            }
            Collections.sort(list);
            list.add(r.nextInt(16) + 1);
            try {
                ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream("D:\\rubbish\\shuangseqiu.txt"));
                oo.writeObject(list);
                oo.close();
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        }
    }
}
